<?php

	class ModuleFileModel
	{
		public function select()
		{
			
		}
		
		public function create()
		{
			return 1;
		}
		
		public function delete($vo)
		{
			$module = $vo->module;
			$name = $vo->filename;
			$type = $vo->type;
			
			if (strpos($name,'.') > 0)
			{
				$name = substr($name,0,strpos($name,'.') - 1);
			}
return eb_module_file($module,$name,$type);
			return @unlink(eb_module_file($module,$name,$type));
		}
		
		public function insert($vo)
		{
			$module = $vo->module;
			$name = $vo->filename;
			$type = $vo->type;
			$content = isset($vo->content) ? $vo->content : '';
			$extends = isset($vo->extends) ? $vo->extends : '';
			$ltype = strtolower($type);
			
			$file = eb_module_file($module,$name,$type);
					
			if (!is_file($file))
			{
				$filecontent = "";
			
				if ($ltype === "command")
				{
					$filecontent = file_get_contents(EBUILDY_PATH."template/command.txt");
				}
				elseif ($ltype === "filter")
				{
					$filecontent = file_get_contents(EBUILDY_PATH."template/filter.txt");
				}
				elseif ($ltype === "vo")
				{
					$filecontent = file_get_contents(EBUILDY_PATH."template/vo.txt");
				}
				elseif ($ltype === "model")
				{
					$filecontent = file_get_contents(EBUILDY_PATH."template/model.txt");
				}
				elseif ($ltype === "table")
				{
					$filecontent = file_get_contents(EBUILDY_PATH."template/table.txt");
				}
				elseif ($ltype === 'component')
				{
					$filecontent = '{content}';
				}
				
				$filecontent = str_replace("{name}",$name,$filecontent);
				$filecontent = str_replace("{content}",$content,$filecontent);
				$filecontent = str_replace("{extends}",$extends,$filecontent);
							
				return file_put_contents($file,$filecontent) !== FALSE;
			}
			
			return false;
		}
	
	}